package chapter06;

public class Java07_Exception {
    public static void main(String[] args) {
        //  TODO 异常
        String account = "admin";
        String password = "admin";
        try {
            login(account,password);
        } catch (AccountException accountException) {
            System.out.println("账号错误，请修改");
        } catch (PasswordException passwordException){
            System.out.println("密码错误，请修改");
        } catch (LoginException loginException){
            System.out.println("其他登录错误，需要确认");
        }

    }

    public static void login(String account,String password) {
//    public static void login(String account,String password) throws AccountException, PasswordException{
//    public static void login(String account,String password) throws LoginException{
        if (!"admin".equals(account)) {
            throw new AccountException("账号错误");
        }
        if (!"admin".equals(password)) {
            throw new PasswordException("密码错误");
        }
        System.out.println("登录成功");
    }

}
// TODO 自定义异常
class LoginException extends RuntimeException {
//class LoginException extends Exception {
    public LoginException(String message) {
        super(message);
    }
}

class AccountException extends LoginException {
    public AccountException(String message) {
        super(message);
    }
}

class PasswordException extends LoginException {
    public PasswordException(String message) {
        super(message);
    }
}